/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slisfx.devices;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import slisfx.Globals;
import slisfx.resources.Load;
import slisfx.screens.DeviceViewAdminFX;

/**
 *
 * @author ITC
 */
public class LightViewAdminFX extends Application implements Globals  {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(final Stage primaryStage) {
        try {
            primaryStage.setTitle("Lights menu");
            primaryStage.setResizable(false);
            
            /*
             * Here we will declare all the functions for our Screen.
             */
            
            /*
             *THIS IS THE CORRECT WAY TO CALL AN IMAGE FROM A PACKAGE
             *VERY EASY UNLIKE EVERY FOURM SAYS!
             */
            
            Image image = new Image(new Load().loadFile("gray.png"));
            Image image1 = new Image(new Load().loadFile("NASA_IVV1_sm.png"));
            Image image2 = new Image(new Load().loadFile("WVU_LOGO_sm.png"));

            BorderPane mainWindow = new BorderPane();
            
            
            
            mainWindow.setTop(new Rectangle(830,50, Color.BLACK));
            mainWindow.setBottom(new Rectangle(830,50, Color.BLACK));
            mainWindow.setLeft(new Rectangle(50,350, Color.BLACK));
            mainWindow.setRight(new Rectangle(50, 350, Color.BLACK));
            
            //This is for the background
            StackPane stackPane = new StackPane();
            
            //This is for horizantal layout.
            HBox imageBox = new HBox();
            imageBox.setPadding(new Insets(10, 10, 10, 200));
            imageBox.setSpacing(100);
            
            //This is a function for Images
            ImageView iv1BackGround = new ImageView();
            ImageView iv2 = new ImageView();
            ImageView iv3 = new ImageView();
            iv1BackGround.setImage(image);
            iv2.setImage(image1);
            iv3.setImage(image2);
            
            imageBox.getChildren().addAll(iv2, iv3);
            
    //        Slider slider = new Slider(0, 1, 0.5);
    //        slider.setShowTickMarks(true);
    //        slider.setShowTickLabels(true);
    //        slider.setMajorTickUnit(0.25f);
    //        slider.setBlockIncrement(0.1f);
           
           
            
            Button btn = new Button();
            Button btn2 = new Button();
            Button btn3 = new Button();
            Button btn4 = new Button();
            Button btn5 = new Button();
            btn.setText("Light On");
            btn2.setText("Light Off");
            btn3.setText("Brighten");
            btn4.setText("Dim");
            btn5.setText("Return");
           
            final CheckBox cb = new CheckBox("Light 1");
            final CheckBox cb2 = new CheckBox("Light 2");
            final CheckBox cb3 = new CheckBox("Light 3");
            cb.setTextFill(Color.WHITE);
            cb2.setTextFill(Color.WHITE);
            cb3.setTextFill(Color.WHITE);

            
            btn.setOnAction(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    if(cb.isSelected()){
                        System.out.println("Light 1 is now on");
                        x10.x10on('E',2);
                    }
                    
                    if(cb2.isSelected()){
                        System.out.println("Light 2 is now on");
                        x10.x10on('E',3);
                    }
                    
                    if(cb3.isSelected()){
                        System.out.println("Light 3 is now on");
                        x10.x10on('E',4);
                    }
                }
            });
            
            btn2.setOnAction(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    if(cb.isSelected()){
                        System.out.println("Light 1 is now off");
                        x10.x10off('E',2);
                    }
                    
                    if(cb2.isSelected()){
                        System.out.println("Light 2 is now off");
                        x10.x10off('E',3);
                    }
                    
                    if(cb3.isSelected()){
                        System.out.println("Light 3 is now off");
                        x10.x10off('E',4);
                    }
                }
            });
            
            btn3.setOnAction(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    if(cb.isSelected()){
                        System.out.println("Light 1 is now brighting");
                        x10.x10brighten('E',2);
                    }
                    
                    if(cb2.isSelected()){
                        System.out.println("Light 2 is now brighting");
                        x10.x10brighten('E',3);
                    }
                    
                    if(cb3.isSelected()){
                        System.out.println("Light 3 is now brighting");
                        x10.x10brighten('E',4);
                    }
                }
            });
            
            btn4.setOnAction(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    if(cb.isSelected()){
                        System.out.println("Light 1 is now dimming");
                        x10.x10dim('E',2);
                    }
                    
                    if(cb2.isSelected()){
                        System.out.println("Light 2 is now dimming");
                        x10.x10dim('E',3);
                    }
                    
                    if(cb3.isSelected()){
                        System.out.println("Light 3 is now dimming");
                        x10.x10dim('E',4);
                    }
                }
            });
            
            btn5.setOnAction(new EventHandler<ActionEvent>() {

                @Override
                public void handle(ActionEvent event) {
                    new DeviceViewAdminFX().start(primaryStage);
                }
            });
            
    //        slider.valueProperty().addListener(new ChangeListener<Number>() {
    //            @Override
    //            public void changed(ObservableValue<? extends Number> ov,
    //                Number old_val, Number new_val) {
    //                
    //                if(cb.isSelected()){
    //                    System.out.println("Light 1 dimness changed to " + new_val);}
    //                
    //                if(cb2.isSelected()){
    //                    System.out.println("Light 2 dimness changed to " + new_val);}
    //                
    //                if(cb3.isSelected()){
    //                    System.out.println("Light 3 dimness changed to " + new_val);}
    ////                   
    //            }
    //        });
            
            
            HBox ckboxes = new HBox();
            ckboxes.setPadding(new Insets(10, 10, 10, 260));
            ckboxes.setSpacing(20);
            
            ckboxes.getChildren().add(cb);
            ckboxes.getChildren().add(cb2);
            ckboxes.getChildren().add(cb3);
            
            HBox onOffBut = new HBox();
            onOffBut.setPadding(new Insets(10, 10, 10, 120));
            onOffBut.setSpacing(50);
            onOffBut.getChildren().add(btn);
            onOffBut.getChildren().add(btn2);
            onOffBut.getChildren().add(btn3);
            onOffBut.getChildren().add(btn4);
            onOffBut.getChildren().add(btn5);
            
    //        HBox dimOrBright = new HBox();
    //        onOffBut.setPadding(new Insets(10, 10, 10, 10));
    //        onOffBut.setSpacing(50);
    //        onOffBut.getChildren().add(btn3);
    //        onOffBut.getChildren().add(btn4);
            
            
            VBox mainMenu = new VBox();
            mainMenu.setPadding(new Insets(10, 10, 10, 10));
            mainMenu.setSpacing(30);
            Text title = new Text("Lights menu");
            title.setFont(Font.font("Amble CN", FontWeight.BOLD, 14));
            title.setFill(Color.WHITE);
            mainMenu.getChildren().addAll(title, imageBox, ckboxes);
            //mainMenu.getChildren().add(slider);
            //mainMenu.getChildren().add(dimOrBright);
            mainMenu.getChildren().add(onOffBut);
            
            stackPane.getChildren().addAll(iv1BackGround, mainMenu);
            mainWindow.setCenter(stackPane);

            primaryStage.setScene(new Scene(mainWindow, WIDTH, HEIGHT));
            primaryStage.show();
        } catch (IOException ex) {
            Logger.getLogger(LightViewAdminFX.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
